package com.itheima.test;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

/***
 *@title MyJFrame
 *@description <TODO description class purpose>
 *@author 12468
 *@version 1.0.0
 *@create 2024-11-07 23:26
 **/
public class MyJFrame3 extends JFrame  implements KeyListener {

    public MyJFrame3() throws HeadlessException {
        //设置界面的宽高
        this.setSize(603, 680);
        //设置界面的标题
        this.setTitle("拼图单机版 v1.0");
        //设置界面置顶
        this.setAlwaysOnTop(true);
        //设置界面居中
        this.setLocationRelativeTo(null);
        //设置关闭模式
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //取消默认的居中放置，只有取消了才会按照XY轴的形式添加组件
        this.setLayout(null);

        // 给界面键盘事件
        this.addKeyListener(this);

        this.setVisible(true);
    }

    @Override
    public void keyTyped(KeyEvent e) {

    }

    @Override
    public void keyPressed(KeyEvent e) {
        System.out.println("键盘按下");
    }

    @Override
    public void keyReleased(KeyEvent e) {
        System.out.println("键盘松开");
        int keyCode = e.getKeyCode();
        System.out.println(keyCode);
        if(keyCode == 65) {
            System.out.println("键盘按下a");
        }
    }
}
